package com.mia.props.client.container;

import com.mia.props.common.entities.TileContainer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;

public class GuiChestProps extends GuiContainer {
   private static final ResourceLocation background = new ResourceLocation("props:textures/gui/decogui1.png");
   protected int xSize = 176;
   protected int ySize = 183;
   protected InventoryPlayer inventory;
   protected TileContainer tileEntity;
   private int invX;
   private int invY = 0;
   private int topMainInv;
   private int leftMainInv = 0;
   private int topHotbarInv;
   private int leftHotbarInv = 0;
   private int topPlayerInv;
   private int leftPlayerInv = 0;

   public GuiChestProps(Container container, InventoryPlayer inventory, TileEntity te) {
      super(container);
      this.inventory = inventory;
      this.tileEntity = (TileContainer)te;
      this.invX = this.tileEntity.getSizeInventoryX();
      this.invY = this.tileEntity.getSizeInventoryY();
      int widthSlots = this.invX * 18;
      int heightSlots = this.invY * 18;
      this.leftMainInv = (this.xSize - widthSlots) / 2;
      this.leftHotbarInv = (this.xSize - 162) / 2;
      this.topPlayerInv = (this.xSize - 162) / 2;
   }

   protected void drawGuiContainerForegroundLayer(int param1, int param2) {
      GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
      this.mc.getTextureManager().bindTexture(background);

      int y;
      int x;
      for(y = 0; y < this.invX; ++y) {
         for(x = 0; x < this.invY; ++x) {
            this.drawTexturedModalRect(this.leftMainInv + y * 18, this.topMainInv + x * 18, 176, 0, 18, 18);
         }
      }

      for(y = 0; y < 9; ++y) {
         this.drawTexturedModalRect(this.leftHotbarInv + y * 18, 150, 176, 0, 18, 18);
      }

      for(y = 0; y < 3; ++y) {
         for(x = 0; x < 9; ++x) {
            this.drawTexturedModalRect(this.leftHotbarInv + x * 18, 94 + 18 * y, 176, 0, 18, 18);
         }
      }

   }

   protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
      GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
      this.mc.getTextureManager().bindTexture(background);
      int k = (this.width - this.xSize) / 2;
      int l = (this.height - this.ySize) / 2;
      this.drawTexturedModalRect(k, l, 0, 0, this.xSize, 183);
   }
}
